﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using SaludOcupacional.Model;
using SaludOcupacional.Controller;

namespace SaludOcupacional
{
    /// <summary>
    /// Interaction logic for BuscarEmpleado2.xaml
    /// </summary>
    public partial class BuscarEmpleado2 : Window
    {

        public Empleado empleado;
        public BuscarEmpleado2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (cNombre.Text == "")
            {
                MessageBox.Show("Ingrese El Nombre!");
            }
            else
            {
                Collection<Empleado> lista = new Collection<Empleado>();
                lista = EmpleadoManager.BuscarEmpleadoPorNombre(cNombre.Text);

                if (lista.Count > 0)
                {
                    int i = 0;
                    nombre1.Visibility = Visibility.Visible;
                    nombre1.Content = lista[i].Nombre + " " + lista[i].ApellidoPaterno + " " + lista[i].ApellidoMaterno;
                    ci1.Visibility = Visibility.Visible;
                    ci1.Content = lista[i].Ci;

                    seleccionar1.Visibility = Visibility.Visible;
                    i++;

                    if (lista.Count > 1)
                    {
                        nombre2.Visibility = Visibility.Visible;
                        nombre2.Content = lista[i].Nombre + " " + lista[i].ApellidoPaterno + " " + lista[i].ApellidoMaterno;
                        ci2.Visibility = Visibility.Visible;
                        ci2.Content = lista[i].Ci;

                        seleccionar2.Visibility = Visibility.Visible;
                    }

                    else
                    {
                        nombre2.Visibility = Visibility.Hidden;
                        ci2.Visibility = Visibility.Hidden;

                        seleccionar2.Visibility = Visibility.Hidden;

                        nombre3.Visibility = Visibility.Hidden;
                        ci3.Visibility = Visibility.Hidden;

                        seleccionar3.Visibility = Visibility.Hidden;

                        nombre4.Visibility = Visibility.Hidden;
                        ci4.Visibility = Visibility.Hidden;

                        seleccionar4.Visibility = Visibility.Hidden;

                        nombre5.Visibility = Visibility.Hidden;
                        ci5.Visibility = Visibility.Hidden;

                        seleccionar5.Visibility = Visibility.Hidden;

                    }
                    i++;
                    if (lista.Count > 2)
                    {
                        nombre3.Visibility = Visibility.Visible;
                        nombre3.Content = lista[i].Nombre + " " + lista[i].ApellidoPaterno + " " + lista[i].ApellidoMaterno;
                        ci3.Visibility = Visibility.Visible;
                        ci3.Content = lista[i].Ci;

                        seleccionar3.Visibility = Visibility.Visible;
                    }
                    else
                    {

                        nombre3.Visibility = Visibility.Hidden;
                        ci3.Visibility = Visibility.Hidden;

                        seleccionar3.Visibility = Visibility.Hidden;

                        nombre4.Visibility = Visibility.Hidden;
                        ci4.Visibility = Visibility.Hidden;

                        seleccionar4.Visibility = Visibility.Hidden;

                        nombre5.Visibility = Visibility.Hidden;
                        ci5.Visibility = Visibility.Hidden;

                        seleccionar5.Visibility = Visibility.Hidden;
                    }
                    i++;
                    if (lista.Count > 3)
                    {
                        nombre4.Visibility = Visibility.Visible;
                        nombre4.Content = lista[i].Nombre + " " + lista[i].ApellidoPaterno + " " + lista[i].ApellidoMaterno;
                        ci4.Visibility = Visibility.Visible;
                        ci4.Content = lista[i].Ci;

                        seleccionar4.Visibility = Visibility.Visible;
                    }
                    else
                    {


                        nombre4.Visibility = Visibility.Hidden;
                        ci4.Visibility = Visibility.Hidden;

                        seleccionar4.Visibility = Visibility.Hidden;

                        nombre5.Visibility = Visibility.Hidden;
                        ci5.Visibility = Visibility.Hidden;

                        seleccionar5.Visibility = Visibility.Hidden;
                    }
                    i++;
                    if (lista.Count > 4)
                    {
                        nombre5.Visibility = Visibility.Visible;
                        nombre5.Content = lista[i].Nombre + " " + lista[i].ApellidoPaterno + " " + lista[i].ApellidoMaterno;
                        ci5.Visibility = Visibility.Visible;
                        ci5.Content = lista[i].Ci;

                        seleccionar5.Visibility = Visibility.Visible;
                    }
                    else
                    {

                        nombre5.Visibility = Visibility.Hidden;
                        ci5.Visibility = Visibility.Hidden;

                        seleccionar5.Visibility = Visibility.Hidden;
                    }

                }
                else
                {
                    nombre1.Visibility = Visibility.Hidden;
                    ci1.Visibility = Visibility.Hidden;

                    seleccionar1.Visibility = Visibility.Hidden;

                    nombre2.Visibility = Visibility.Hidden;
                    ci2.Visibility = Visibility.Hidden;

                    seleccionar2.Visibility = Visibility.Hidden;

                    nombre3.Visibility = Visibility.Hidden;
                    ci3.Visibility = Visibility.Hidden;

                    seleccionar3.Visibility = Visibility.Hidden;

                    nombre4.Visibility = Visibility.Hidden;
                    ci4.Visibility = Visibility.Hidden;

                    seleccionar4.Visibility = Visibility.Hidden;

                    nombre5.Visibility = Visibility.Hidden;
                    ci5.Visibility = Visibility.Hidden;

                    seleccionar5.Visibility = Visibility.Hidden;



                    MessageBox.Show("No se encontro Resultados!");
                }
            }
        }

        private void seleccionar1_Click(object sender, RoutedEventArgs e)
        {
            empleado = EmpleadoManager.GetEmpleadoByCi(ci1.Content.ToString());
            Close();
            

        }


        public Empleado devolverEmpleado()
        {
            return empleado;
        }
    }
}
